package com.cheyun.netsalev3.repository

import com.cheyun.netsalev3.bean.DataXX
import com.cheyun.netsalev3.bean.HomeListParam
import com.cheyun.netsalev3.utils.api.ApiCallback
import com.cheyun.netsalev3.utils.api.ApiClient
import com.cheyun.netsalev3.utils.api.ApiException
import com.cheyun.netsalev3.utils.api.BaseResp
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import org.json.JSONObject
import kotlin.reflect.KFunction1

class WorkSwitchRepository {
    fun setWorkbench(uid: Int, workbench: Int, kFunction1: KFunction1<@ParameterName(name = "workbench") Int, Unit>) {
        ApiClient.getInstance().setWorkbench(uid, workbench)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<List<JSONObject>>>() {
                    override fun onSuccess(t: BaseResp<List<JSONObject>>) {
                        kFunction1(workbench)
                    }

                    override fun onError(ex: ApiException) {

                    }


                })
    }

    /**
     * 获取工作台列表
     */
    fun getHomeList(uid: Int, kFunction1: KFunction1<@ParameterName(name = "list") List<DataXX>, Unit>) {
        ApiClient.getInstance().getHomeList(uid)
                .subscribeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .subscribe(object : ApiCallback<BaseResp<HomeListParam>>() {
                    override fun onSuccess(t: BaseResp<HomeListParam>) {
                        t.data?.rows?.apply(kFunction1)
                    }

                    override fun onError(ex: ApiException) {

                    }


                })
    }


}